﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace EnsureWeb.Controls
{
    public class Loading : ContentControl
    {
        public Loading()
            : base()
		{
            this.DefaultStyleKey = typeof(Loading);  
		}

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.storyboard = this.GetTemplateChild("storyboard") as Storyboard;
            this.Visibility = Visibility.Collapsed;
        }

        public void Show(object content)
        {
            if (this.storyboard == null)
                return;
            
            this.Content = content;
            this.Visibility = Visibility.Visible;
            this.storyboard.Begin();
        }

        public void Hide()
        {
            if (this.storyboard == null)
                return;
            
            this.Content = null;
            this.Visibility = Visibility.Collapsed;
            this.storyboard.Stop();
        }

        private Storyboard storyboard;
    }
}
